package app.netant.book.zw34;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;

public class Zw34Detail extends BaseDetail {

	public Zw34Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.34zw.net";
	}

	@Override
	public void analyseTitle() {
		
		Elements parts = this.select(".main #centerm .bdsub #content dd h1");
		if(parts.size()>0){
			
			String title = parts.get(0).text().trim();
			System.out.println("【Title】:"+title);
			
			String name = this.entity.getNovelName();
			if(name ==null || "".equals(name)){
				this.entity.setNovelName(title);
			    this.entity.setNovelFullName(title+".txt");
			}
			
		}

	}

	@Override
	public void analyseTags() {
		
		Elements tds = this.select(".main #centerm .bdsub #content dd table[cellspacing='1'][cellpadding='0'] tbody tr td");
		Elements ths = this.select(".main #centerm .bdsub #content dd table[cellspacing='1'][cellpadding='0'] tbody tr th");
		for(int i=0;i<tds.size();i++){
			String tagName = ths.get(i).text();
			String tagValue = tds.get(i).text();
			System.out.println("【Tag】："+tagName+"="+tagValue);
			this.entity.setTag(tagName, tagValue);
		}
		
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main #centerm .bdsub #content dd p.p1 b");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text().trim();
			if(text.endsWith("内容简介：")){
				Elements pparts = parts.get(i).parent().parent().select("p");
				if(pparts.size()>1){
					String memo = pparts.get(1).text();
					System.out.println("【Memo】:"+memo);
					this.entity.setNovelMemo(memo);
				}
				break;
			}
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main #centerm .bdsub #content dd p.btnlinks a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text().trim();
			if("TXT下载".equals(text)){
				
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				
				System.out.println("【Href】:"+href);
				
				this.entity.setDownPath(href);
				
				break;
			}
		}
	}
	
	@Override
	public void analyseType() {
		
	}
	
	public static void main(String[] args) {
		Zw34Detail detail = new Zw34Detail("https://www.34zw.net/info/107463.html");
		detail.test();
	}



}
